;solution for euler 48
(defun square (a) (* a a))

;from euler 181
(defun cong-expt (base ex m)
	(when (= ex 0) (return-from cong-expt 1))
	(if (= 0 (mod ex 2))
		(return-from cong-expt
			(mod (square (cong-expt base (/ ex 2) m)) m))
		(return-from cong-expt
			(mod (* (cong-expt base (- ex 1) m) base) m))))
			
(defun solve-euler48 ()
	(let ((lastdigits 0) (modulus (expt 10 10)))
		(loop for i from 1 to 1000 do
			(setf lastdigits (mod (+ lastdigits (cong-expt i i modulus)) modulus)))
		(format t "Euler 48: ~a" lastdigits)))